package com.spzx.cart.controller;

import com.spzx.api.domain.CartInfo;
import com.spzx.cart.service.CartService;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
public class CartController extends BaseController {

    @Autowired
    private CartService  cartService;

    @Operation(summary = "将指定商品加入到购物车")
    @GetMapping("/addToCart/{skuId}/{skuNum}")
    public AjaxResult addToCart(@PathVariable Long skuId, @PathVariable Integer skuNum) {
        cartService.addToCart(skuId, skuNum);
        return AjaxResult.success();
    }
    @GetMapping("/cartList")
    public AjaxResult getCartList(){
       List<CartInfo> cartList = cartService.getCartList();
       return AjaxResult.success(cartList);
    }
    @DeleteMapping("/deleteCart/{skuId}")
    public AjaxResult deleteCart(@PathVariable Long skuId){
        cartService.deleteCart(skuId);
        return AjaxResult.success();
    }
    @GetMapping("checkCart/{skuId}/{isChecked}")
    public AjaxResult checkCart(
            @PathVariable("skuId") Long skuId,
            @PathVariable("isChecked") Integer isChecked
    ){
        cartService.checkCartStatus(skuId,isChecked);
        return AjaxResult.success();
    }
    @GetMapping("/allCheckCart/{isChecked}")
    public AjaxResult allCheckCart(@PathVariable Integer isChecked){
        cartService.allCheckCart(isChecked);
        return AjaxResult.success();
    }
    @GetMapping("/clearCart")
    public AjaxResult clearCart(){
        cartService.clearCart();
        return AjaxResult.success();
    }
}
